<script src="https://unpkg.com/qiniu-js@2.5.3/dist/qiniu.min.js"></script>
<script type="text/javascript">
var tokenUrl = '/yq/api/file/token'
var host = 'http://lets.zhen-yee.com/'
var prefix = 'youqu2/'

function guid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random() * 16 | 0,
            v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}


function uploadQnFile(file) {
    const loading = vue.$loading({
        lock: true,
        text: 'Loading',
        // spinner: 'el-icon-loading',
        // background: 'rgba(0, 0, 0, 0.7)'
    });
    axios({
            method: 'get',
            url: tokenUrl,
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
        .then(function(res) {
            var token = res.data.info
            var imageKey = prefix + guid()
            var imageUrl = host + imageKey

            var observer = {
                next(res) {
                    // console.log(res)
                },
                error(err) {
                    // console.log('error')
                    // console.log(res)
                    loading.close();
                },
                complete(res) {
                    // console.log('complete')
                    // console.log(res)
                    var map = {
                        data: {
                            url: imageUrl
                        }
                    }
                    file.onSuccess(map, file.file)
                    loading.close();
                }
            }
            var config = {
                useCdnDomain: true,
                region: qiniu.region.z2
            };
            var observable = qiniu.upload(file.file, imageKey, token, null, null)
            var subscription = observable.subscribe(observer) // 上传开始
        })
}
// var observable = qiniu.upload(file, key, token, putExtra, config)
</script>